package com.hm.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hm.dao.StudentMapper;
import com.hm.pojo.Curriculum;
import com.hm.pojo.ResponseData;
import com.hm.pojo.Result;
import com.hm.pojo.Student;
import com.hm.service.Impl.StudentServiceImpl;
import com.hm.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * This class is for com.hm.web.servlet
 *
 * @author 李聪
 * @version 2023/10/21
 */
@WebServlet("/user/*")
public class StudentServlet extends BaseServlet{
    private StudentService studentService = new StudentServiceImpl();

    private ObjectMapper objectMapper = new ObjectMapper();
    public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username+password);
        Student login = studentService.login("2020010101", "123456");
        Result<Student> success = ResponseData.success(login);
        String s = objectMapper.writeValueAsString(success);
        System.out.println(s);
        resp.getWriter().write(s);

    }

    public void show_curriculum(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //根据学生班级id展示课程表
        List<Curriculum> curriculumList = studentService.show_curriculum("20200101");


        Map<String,List<Curriculum>> map = new HashMap<>();
        map.put("countData",curriculumList);
        Result<Map<String,List<Curriculum>>> success = ResponseData.success(map);
        String s = objectMapper.writeValueAsString(success);
        resp.getWriter().write(s);

    }

/*    public void find_Old_CurriculumById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //根据学生id查询到所有的课程，筛选上过的课程
         List<Curriculum> curriculumList=studentService.find_Old_CurriculumById("2020010101");
         Map<String,List<Curriculum>> map=new HashMap<>();
         map.put("countData",curriculumList);
         Result<Map<String,List<Curriculum>>> success = ResponseData.success(map);
         String s = objectMapper.writeValueAsString(success);
         resp.getWriter().write(s);
    }*/
}
